<?php

	require "includes/class.template.php";
	$template = new verySimpleTemplate();

	function getFile($url) 
	{ 
		if($f=@fopen("$url","r")) 
		{ 
			while(!@feof($f)) 
		{ 
		$s.=@fgets($f); 
		} 
			@fclose($f); 
		} 
		return $s; 
	} 


	function showtq( $city )
	{
		global $template;

		if( $city == "")
		{
			$city="北京";
		}

		$allHtml = getFile("http://weather.cn.yahoo.com/weather.html?city=" . $city );
#		$startIndex = strpos($allHtml,'<div id="map" class="map">');
		if(strpos($allHtml, '对不起') >0)
		{
			$myHtml = "对不起，没有找您查询的城市信息";
		}
		else
		{
			$startIndex = strpos($allHtml,'<div class="yui-m">');
			$endIndex = strpos($allHtml,'<div class="yui-s">');

//			$ad1SIndex = strpos($allHtml,"<!--#ads -->");
//			$ad1EIndex = strpos($allHtml,"<!--//ads -->");
			 
			$myHtml = substr($allHtml, $startIndex, $endIndex - $startIndex);
		}

			$template->deal( 'template/header.tpl' );
			$h = $template->template;
			
			$s1 = '';//'<link href="http://cn.yimg.com/i/css/ycomm.css" rel="stylesheet" type="text/css" media="screen" />';
			$s2 = '';//'<link href="http://cn.yimg.com/i/css/pstru2.1.css" rel="stylesheet" type="text/css" media="screen" />';
			$s3 = '';//'<link href="http://cn.yimg.com/i/css/yui/ygrids.css" rel="stylesheet" type="text/css" media="screen" />';
			$s4 = '';//'<link href="http://cn.yimg.com/i/css/wea/wea2.2.4.css" rel="stylesheet" type="text/css" media="screen" />';

			$arrayVar = array (
								'RESULT'	=> $myHtml
							   );

			$template->deal( 'template/weather.tpl', $arrayVar );
			$b = $template->template;

			$template->deal( 'template/footer.tpl' );
			$f = $template->template;

			echo $h . $s1. $s2. $s3. $s4. $b . $f;
	}

	showtq($_POST['city']);

?>